//丢失的数字
//测试链接 https://leetcode.cn/problems/missing-number/
public class MissingNumber {

    //高斯求和
    public int missingNumber1(int[] nums) {
        int n = nums.length;
        int sum = (0 + n) * (n+1) / 2;
        for(int i = 0 ; i < n; i++){
            sum -= nums[i];
        }
        return sum;
    }

    //位运算
    public int missingNumber(int[] nums) {
        int n =nums.length;
        int ret = 0;
        for(int i = 0; i < n; i++){
            ret =ret ^ nums[i] ^ i;
        }
        return ret ^ n;
    }
}
